package org.nutz.stu.filter;

import javax.servlet.http.HttpSession;

import org.nutz.mvc.ActionContext;
import org.nutz.mvc.ActionFilter;
import org.nutz.mvc.Mvcs;
import org.nutz.mvc.View;
import org.nutz.mvc.view.ForwardView;

/**
 * @Auther: xiaoyuan
 * @Date: 2019/1/21
 * @Description:
 */
public class SessionFilter implements ActionFilter {

    private String name;
    private String path;

    public SessionFilter(String name, String path) {
        this.name = name;
        this.path = path;
    }

    @Override
    public View match(ActionContext context) {
        HttpSession session = Mvcs.getHttpSession(false);
        return session != null && null != session.getAttribute(this.name)?null:new ForwardView(path);
    }
}
